<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>数组</title>
		<script type="text/javascript">
					var arr = [1, 4, 3, 2, 5, 5];
					console.log("原数组arr[" + arr + "]");
		
					//筛选数组元素：
					console.log("筛选小于等于3数组元素：")
					for (var i = 0; i <= arr.length - 1; i++) {
						if (arr[i] <= 3) {
							console.log(arr[i]);
						}
					}
		
					//翻转数组(双指针)：
					console.log("双指针翻转数组：")
					var left = 0;
					var right = arr.length - 1;
					while (left < right) {
						var temp;
						temp = arr[left];
						arr[left] = arr[right];
						arr[right] = temp;
						left++;
						right--;
					}
					console.log(arr);
		
					//翻转数组(首尾交换)：
					console.log("首尾交换翻转数组:")
					for (var i = 0; i <= Math.ceil(arr.length / 2) - 1; i++) {
						var temp;
						temp = arr[i];
						arr[i] = arr[arr.length - 1 - i];
						arr[arr.length - 1 - i] = temp;
					}
					console.log(arr);
		
					//数组求和、求最大值：
					console.log("数组求和、求最大值:");
					var maxIndex = 0;
					var count = 0;
					for (var i = 0; i <= arr.length - 1; i++) {
						count += arr[i];
						if (arr[maxIndex] < arr[i]) {
							maxIndex = i;
						}
					}
					console.log("数组和与最大值分别为" + count + " " + arr[maxIndex]);
		
					//冒泡排序升序：
					console.log("冒泡排序升序");
					for (var i = 1; i <= arr.length - 1; i++) {
						for (var j = 0; j <= arr.length - i; j++) {
							if (arr[j] > arr[j + 1]) {
								var temp;
								temp = arr[j];
								arr[j] = arr[j + 1];
								arr[j + 1] = temp;
							}
						}
					}
					console.log("冒泡排序结果" + arr);
		
					//数组去重集合：
					console.log("数组去重:");
					console.log("去重之前数组：" + arr);
					var myset = new Set(arr);
					arr = [];
					for (var i of myset) {
						arr.push(i);
					}
					console.log("去重之后数组：" + arr);
				</script>
	</head>
	<body>
		
	</body>
</html>
